﻿using System.Diagnostics.CodeAnalysis;
using Moq;

namespace UnitTesting.Fixturing.Moq
{
	public static class FixtureExtensions
	{
		[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
		public static Mock<T> WithDefaultValueAsMock<T>(this Mock<T> mock) where T : class
		{
			Ensure.IsNotNull(mock, "mock").DefaultValue = (DefaultValue) FixtureMockDefaultValue.Mock;
			return mock;
		}

		[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
		public static Mock<T> WithDefaultValueAsEmpty<T>(this Mock<T> mock) where T : class
		{
			Ensure.IsNotNull(mock, "mock").DefaultValue = (DefaultValue) FixtureMockDefaultValue.Empty;
			return mock;
		}

		[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
		public static Mock<T> WithDefaultValueAsFixture<T>(this Mock<T> mock) where T : class
		{
			Ensure.IsNotNull(mock, "mock").DefaultValue = (DefaultValue) FixtureMockDefaultValue.Fixture;
			return mock;
		}

		[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
		public static Mock<T> WithCallBaseAsTrue<T>(this Mock<T> mock) where T : class
		{
			Ensure.IsNotNull(mock, "mock").CallBase = true;
			return mock;
		}

		[SuppressMessage("Microsoft.Design", "CA1011:ConsiderPassingBaseTypesAsParameters")]
		public static Mock<T> WithCallBaseAsFalse<T>(this Mock<T> mock) where T : class
		{
			Ensure.IsNotNull(mock, "mock").CallBase = false;
			return mock;
		}

		public static Mock<T> ToMock<T>(this T instance) where T : class
		{
			return Mock.Get(instance);
		}
	}
}